package jay9downloader;

/**
 *
 * @author Anders
 */
public class ConsoleProgress {
    private int ticks;
    private int progress;
    private int length;

    /**
     *
     * @param total Total number of ticks before completion of task
     * @param ticks How often to display progress
     */
    public ConsoleProgress(int total, int ticks){
        this.ticks = ticks;

        length = total / ticks;
    }

    public void tick(){
        progress++;

        if (progress % ticks == 0){
            System.out.print("Loading: [");

            int tickProgress = progress / ticks;

            for (int i = 0; i < tickProgress; ++i){
                System.out.print("*");
            }
            for (int i = 0; i < length - tickProgress; ++i){
                System.out.print(".");
            }

            System.out.println("]");
        }
    }
}
